package meterMonitor.service;

import meterMonitor.mapper.LineMapper;
import meterMonitor.mapper.ProductivityMapper;
import meterMonitor.model.LinePO;
import meterMonitor.model.ProductivityPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductivityService {

    @Autowired
    ProductivityMapper productivityMapper;

    @Autowired
    LineMapper lineMapper;


    public void add(ProductivityPO productivity) {
        productivityMapper.add(productivity);
    }

    public void update(ProductivityPO productivity) {
        productivityMapper.update(productivity);
    }

    public List<ProductivityPO> query(ProductivityPO productivity) {
        return productivityMapper.query(productivity);
    }

    public Map<String, List<ProductivityPO>> yieldCount() {
        List<LinePO> lines = lineMapper.queryLine(new LinePO());
        Map<String, List<ProductivityPO>> result = new HashMap<>();
        for (LinePO line : lines) {
            List<ProductivityPO> productivitys = productivityMapper.yieldCountByLineId(line.getId());
            result.put(line.getName(), productivitys);
        }
        return result;
    }

    // public void delete(Productivity productivity) {
    //     productivityMapper.delete(productivity);
    // }

}
